// demo1
const events = require('events');

const myEmitter1 = new events.EventEmitter();

myEmitter1.on('testEvent', function (msg) {
  console.log(msg)
})

myEmitter1.emit('testEvent', 'the event was emitted just now!'); // 手动触发

// demo2
class MyEmitter extends events { };
const myEmitter2 = new MyEmitter()

myEmitter2.on('testFun', function () {
  console.log('the event was emitted')
})

myEmitter2.emit('testFun')